'use strict';
//这是用户自动执行脚本 配合cron使用
const db = uniCloud.database(); //代码块为cdb
exports.main = async (event, context) => {
	const AppID = "wx23b5dafd4b8cca6d"
	const AppSecret = "615cccxxxxxxxxxa50c20b9"
	const access_token = await uniCloud.httpProxyForEip.get('https://api.weixin.qq.com/cgi-bin/token',
	  {
		grant_type: 'client_credential',
		appid: AppID,
		secret:AppSecret
	  }
	)
	const jsapi_ticket = await uniCloud.httpclient.request(`https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=${access_token.body.access_token}&type=jsapi`, {
		method: 'GET',
		data: {
		},  
		dataType: 'json' // 指定返回值为json格式，自动进行parse  
	});
	let datas = {
		currentAccessToken:access_token.body.access_token,
		currentJsapiTicket:jsapi_ticket.data.ticket,
		accessTokenRefreshTime:new Date()
	}
	let tokens = await db.collection('tokens').where({'_id':"6583xxxxxxxxx4b8a0d2"}).update(datas)
};
